package com.zoshine.zzg.factory;

import com.zoshine.zzg.constant.CookieEnum;

import javax.servlet.http.Cookie;

/**
 * cookie工厂
 *
 * @author 贾俊峰
 * @time 2017/7/21 10:41
 */
public class CookieFactory {
    private static final String DEFAULT_PATH = "/";


    public static Cookie createToken(String value) {
        return create(CookieEnum.TOKEN, value, true);
    }
    public static Cookie createSeries(String value) {
        return create(CookieEnum.SERIES, value, true);
    }

    public static Cookie create(CookieEnum cookieEnum, String value, boolean httpOnly) {
        Cookie cookie = new Cookie(cookieEnum.getName(), value);
        cookie.setMaxAge(cookieEnum.getMaxAge());
        cookie.setPath(DEFAULT_PATH);
        cookie.setHttpOnly(httpOnly);
        return cookie;
    }

    public static Cookie delete(CookieEnum cookieEnum) {
        Cookie cookie = new Cookie(cookieEnum.getName(), null);
        cookie.setMaxAge(0);
        cookie.setPath(DEFAULT_PATH);
        return cookie;
    }

}
